package com.key.web_admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.key.common.base.RespResult;
import com.key.modules.dto.SysMenuSelectDTO;
import com.key.modules.entity.SysRole;
import com.key.modules.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author：朕
 * @Package：com.key.web_admin.controller
 * @Project：logistics_system
 * @name：SysRoleController
 * @Date：2023/3/23 20:26
 * @Filename：SysRoleController
 */
@RestController
@RequestMapping("/systemSetting/role")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    /**
     * 显示所有角色
     */
    @GetMapping("/findSysRole")
    public IPage<SysRole> findSysRole(SysMenuSelectDTO sysMenuSelectDTO){
        return sysRoleService.findSysRole(sysMenuSelectDTO);
    }

    /**
     * 新增角色
     */
    @PostMapping("/addSysRole")
    public RespResult addSysUser(SysRole sysRole){
        Boolean s = sysRoleService.addSysRole(sysRole);
        if(s==true){
            return RespResult.success();
        }
        return RespResult.error("添加失败");
    }

    /**
     * 修改角色
     */
    @PostMapping("/updateSysRole")
    public RespResult updateSysUser(SysRole sysRole){
        Boolean s = sysRoleService.updateSysRole(sysRole);
        if(s==true){
            return RespResult.success();
        }
        return RespResult.error("添加失败");
    }

    /**
     * 删除角色
     */
    @PostMapping("/deleteSysRole")
    public RespResult deleteSysRole(Integer roleId){
        Boolean s = sysRoleService.deleteSysRole(roleId);
        if(s==true){
            return RespResult.success();
        }
        return RespResult.error("添加失败");
    }
    /**
     * 新增角色权限
     */
    @PostMapping("/addSysRoleMenu")
    public RespResult addSysRoleMenu(Integer roleId,Integer[] menuId){
        Boolean s = sysRoleService.addSysRoleMenu(roleId,menuId);
        if(s==true){
            return RespResult.success();
        }
        return RespResult.error("添加失败");
    }

}
